package abd.pr1.Controllers;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.sql.DataSource;

import abd.pr1.Interface.AdminActoresPanel;
import abd.pr1.Interface.AdminPersonajesPanel;
import abd.pr1.Interface.NuevoActorWindow;
import abd.pr1.Interface.NuevoPersonajeWindow;
import abd.pr1.Mappers.ActoresMapper;
import abd.pr1.Mappers.PersonajesMapper;
import abd.pr1.Models.Actor;
import abd.pr1.Models.Personaje;

public class AdminActoresPanelController implements ActionListener{

	private AdminActoresPanel adminActoresPanel;
	private DataSource ds;
	
	public AdminActoresPanelController( AdminActoresPanel adminActoresPanel, DataSource ds) {

		this.adminActoresPanel = adminActoresPanel;
		this.ds = ds;
		this.adminActoresPanel.addListener(this);
		this.refreshActores();
	}
	public void refreshActores(){
		List<Actor> actores=new ActoresMapper(ds).buscarNombreActor(adminActoresPanel.getBuscarTexto());
		this.adminActoresPanel.setListaActores(actores);
	}
	
	
	@Override
	public void actionPerformed(ActionEvent e) {
		// TODO Auto-generated method stub
		
		if (e.getActionCommand().equals("buscar_admin_actor")){
			List<Actor> actores=new ActoresMapper(ds).buscarNombreActor(adminActoresPanel.getBuscarTexto());
			this.adminActoresPanel.setListaActores(actores);
		}else if (e.getActionCommand().equals("nuevo_actor")){
			new NuevoActorWindowController(this,new NuevoActorWindow(), ds);
		}else if (e.getActionCommand().equals("info_admin_actor")){
			Actor actorSelected=this.adminActoresPanel.getSelectedActor();
			if(actorSelected!=null){
			new EditarActorWindowController(new NuevoActorWindow(), ds,actorSelected);
			}
		}
		
	}

}
